#ifndef HTTPMGR_H
#define HTTPMGR_H

#include "Singleton.h"
#include <QString>
#include <QUrl>
#include <QObject>
#include <QNetworkAccessManager>
#include "global.h"
#include <memory>
#include <QJsonObject>
#include <QJsonDocument>

//继承QObject是为了使用信号等qt机制，继承Singleton是为了实现单例模式
class HttpMgr:public QObject,public Singleton<HttpMgr>,
        public std::enable_shared_from_this<HttpMgr>
{
    Q_OBJECT
public:
    void PostHttpReq(const QUrl url, const QJsonObject json,
                     const ReqId req_id,const Modules mod);
private:
    friend class Singleton<HttpMgr>;//让Singleton能够访问私有构造函数
    QNetworkAccessManager _manager;
    HttpMgr();//声明为私有构造函数，单例模式

private slots:
    void slot_http_finish(ReqId id,QString str,ErrorCodes er,Modules mod);
signals:
    void sig_reg_mod_finish(ReqId id,QString str,ErrorCodes er);
    void sig_reset_mod_finish(ReqId id,QString str,ErrorCodes er);
    void sig_login_mod_finish(ReqId id,QString str,ErrorCodes er);

    void sig_http_finish(ReqId id,QString str,ErrorCodes er,Modules mod);
};

#endif // HTTPMGR_H
